home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 117 / PC Guia 117.iso / Software / Utils / Software6 / Product2 / adblock-0.5.2.039-fx.xpi / install.js next >
Text File  |  2004-05-30  |  8KB  |  180 lines

  1. /*
  2. ** authored by rue
  3. */
  4.  
  5. /* Pre-Install Cleanup (for prior versions) */
  6.  
  7. // temp-dir
  8. initInstall("pre-install", "/tempDir", "0.0"); // dummy-install - allows committance of file-operations
  9. var tempDir = getFolder(getFolder("Profile", "chrome"), "adblock-temp"); // adblock temp-dir
  10. if (!File.exists(tempDir)) dirCreate(tempDir); // create temp-dir if it doesn't exist
  11. performInstall(); // commit dir-creation changes
  12.  
  13. // file-check array
  14. var dirArray = new Array();
  15. dirArray[0] = new Array();
  16.     dirArray[0].push(getFolder("Profile", "chrome"));    // profile-chrome
  17.     dirArray[0].push("adblock");                         // filename - profile jar
  18.     dirArray[0].push(".jar");                             // filename - extension
  19. dirArray[1] = new Array();
  20.     dirArray[1].push(getFolder("chrome"));                // app-chrome
  21.     dirArray[1].push("adblock");                         // filename - root jar
  22.     dirArray[1].push(".jar");                             // filename - extension
  23. dirArray[2] = new Array();
  24.     dirArray[2].push(getFolder("components"));            // app-components
  25.     dirArray[2].push("nsAdblock");                         // filename - root component
  26.     dirArray[2].push(".js");                             // filename - extension
  27. dirArray[3] = new Array();
  28.     dirArray[3].push(getFolder("Profile"));                // profile
  29.     dirArray[3].push("XUL FastLoad File");                 // filename - xul cache mac
  30.     dirArray[3].push("");                                 // filename - extension
  31. dirArray[4] = new Array();
  32.     dirArray[4].push(getFolder("Profile"));                // profile
  33.     dirArray[4].push("XUL");                             // filename - xul cache macosX
  34.     dirArray[4].push(".mfast");                         // filename - extension
  35. dirArray[5] = new Array();
  36.     dirArray[5].push(getFolder("Profile"));                // profile
  37.     dirArray[5].push("XUL");                             // filename - xul cache linux
  38.     dirArray[5].push(".mfasl");                         // filename - extension
  39. dirArray[6] = new Array();
  40.     dirArray[6].push(getFolder("Profile"));                // profile
  41.     dirArray[6].push("XUL");                             // filename - xul cache windows
  42.     dirArray[6].push(".mfl");                             // filename - extension
  43.  
  44. // file-check loop
  45. for (var i = 0 ; i < dirArray.length ; i++) {
  46.     initInstall("pre-install", "/rename", "0."+i); // reopen dummy-install
  47.     var currentDir = dirArray[i][0];
  48.     var nameMain = dirArray[i][1];
  49.     var nameEnd = dirArray[i][2];
  50.     var tempDir = getFolder(getFolder("Profile", "chrome"), "adblock-temp"); // adblock temp-dir
  51.     if (!File.exists(tempDir)) dirCreate(tempDir); // create temp-dir if it doesn't exist
  52.     var previousFile = getFolder(currentDir, nameMain + nameEnd); // previous jar
  53.     var newNameMain = "adblock-uninstalled";// nameMain + "-uninstalled";
  54.     var newName = newNameMain; // + nameEnd;
  55.     var n = 1;
  56.     
  57.     if (File.exists(previousFile)) {
  58.         if (File.exists(getFolder(currentDir, newName))) // <-- change 'currentDir' to 'tempDir' to revert: old-style
  59.             while(File.exists(getFolder(currentDir, newName))) { // <-- ditto.
  60.                 newName = new String(newNameMain + n); // + nameEnd); // find a unique-name for our "move-to" destination
  61.                 n++;
  62.             }
  63.         // rename file
  64.         File.rename(previousFile, newName); // rename the previous jar to the unique-name
  65.         performInstall(); // commit file-rename changes
  66.         
  67.         // -- this can be (un)commented without worry.. it just seemingly fails to move, every time
  68.         // move file
  69.         initInstall("pre-install", "/move", "0."+i); // reopen dummy-install
  70.         previousFile = getFolder(currentDir, newName); // get prev. version by its new name
  71.         File.move(previousFile, tempDir); // move jar to temp-dir
  72.         performInstall(); // commit file-move changes
  73.         
  74.         // delete original
  75.         initInstall("pre-install", "/delete", "0."+i); // reopen dummy-install
  76.         if (File.exists(previousFile)) File.remove(previousFile); // delete original (in case it didn't completely move)
  77.         performInstall(); // commit file-deletion changes
  78.     }
  79.     
  80. }
  81.  
  82.  
  83. /* Main Install Routine */
  84.  
  85. // only load after the Pre-Install Cleanup completes
  86. if (true) {
  87.     // install constants
  88.     const APP_DISPLAY_NAME = "Adblock";
  89.     const APP_NAME = "adblock";
  90.     const APP_PACKAGE = "/adblock.mozdev.org";
  91.     const APP_VERSION = "0.5";
  92.     
  93.     const APP_JAR_FILE = "adblock.jar";
  94.     const APP_JAR_LOC = 'chrome/' + APP_JAR_FILE;
  95.     
  96.     const APP_COMP_FILE = "nsAdblock.js";
  97.     const APP_COMP_LOC = APP_COMP_FILE;
  98.     
  99.     const APP_CONTENT_FOLDER = "content/";
  100.     
  101.     const INST_TO_PROFILE = "Install "+APP_DISPLAY_NAME+" in your profile?\n(..you wont have to reinstall when updating the browser).\n\nClick Cancel to install "+APP_DISPLAY_NAME+" in the browser root.";
  102.     const ROOT_FAILED___TRY_INST_TO_PROFILE = "You didn't have permission to install as root.\n Would you like to force profile-installation?\n\n[Note: "+APP_DISPLAY_NAME+" WILL NOT FUNCTION in the profile for browsers-builds older than 6.24.03. This includes moz1.4.1 and fb.6]";
  103.     
  104.     const profileChrome = getFolder("Profile", "chrome");
  105.     const previousJarInProfile = getFolder(profileChrome, "adblock.jar");
  106.     const previousJarInRoot = getFolder("chrome", "adblock.jar"); }
  107.  
  108.  
  109.  
  110. // initialize our install
  111. initInstall(APP_NAME, APP_PACKAGE, APP_VERSION);
  112.  
  113.  
  114. // check for previous install
  115. if (File.exists(previousJarInProfile) || File.exists(previousJarInRoot)) {
  116.     
  117.     var installedHere = File.exists(previousJarInProfile)?"profile ":"";
  118.     installedHere += (File.exists(previousJarInProfile) && File.exists(previousJarInRoot))?"*and* ":"";
  119.     installedHere += File.exists(previousJarInRoot)?"root ":"";
  120.     installedHere += (File.exists(previousJarInProfile) && File.exists(previousJarInRoot))?"directories":"directory";
  121.  
  122.     alert("Sorry:  Adblock is already installed in your " + installedHere + ". "
  123.         +"\n\n\n\nIf you're running a recent dev-build, you can deinstall from preferences. "
  124.         +"\nFor all other versions, please consult the online-faq:"
  125.         +"\n\nadblock.mozdev.org/faq.html");
  126.     cancelInstall(-23); // we can't overwrite, so don't install further
  127.     
  128. }
  129. else {
  130.  
  131.     // runtime component registration only works since 2003-06-24..
  132.     var instToProfile = false;
  133.     if (buildID == 0 || buildID > 2003062400) instToProfile = confirm(INST_TO_PROFILE); // ..so, dont ask on prior builds.
  134.     
  135.     
  136.     
  137.     // install component if not installing to profile
  138.     if (!instToProfile) {
  139.         var compf = getFolder("components");
  140.         var errComponent = addFile(APP_PACKAGE, APP_VERSION, APP_COMP_LOC, compf, null); }
  141.     
  142.     // install jar-file
  143.     var chromef = instToProfile ? getFolder("Profile", "chrome") : getFolder("chrome");
  144.     var errJar = addFile(APP_PACKAGE, APP_VERSION, APP_JAR_LOC, chromef, null);
  145.     
  146.     
  147.     
  148.     // if root-install was attempted and failed, ask the user what to do
  149.     if(!instToProfile && (errComponent != SUCCESS || errJar != SUCCESS)) {
  150.         instToProfile = confirm(ROOT_FAILED___TRY_INST_TO_PROFILE);
  151.         if (instToProfile) {
  152.             chromef = getFolder("Profile", "chrome");
  153.             errJar = addFile(APP_PACKAGE, APP_VERSION, APP_JAR_LOC, chromef, null); }
  154.         else errJar = "root install failed";
  155.     }
  156.     
  157.     
  158.     // if we've successfully installed the files, register them
  159.     if (errJar == SUCCESS) {
  160.         var jar = getFolder(chromef, APP_JAR_FILE);
  161.         if (instToProfile) registerChrome(CONTENT | PROFILE_CHROME, jar, APP_CONTENT_FOLDER);
  162.         else registerChrome(CONTENT | DELAYED_CHROME, jar, APP_CONTENT_FOLDER);
  163.     
  164.         var err = performInstall();
  165.         if (err == SUCCESS || err == 999) {
  166.             alert(APP_DISPLAY_NAME + " " + APP_VERSION + " is now installed.\n"
  167.                 +"Just restart to activate."); } 
  168.         else {
  169.             alert("Install failed. Error code:" + err);
  170.             cancelInstall(err); }
  171.     } 
  172.     else {
  173.         alert("Failed to create " +APP_JAR_FILE +"\n"
  174.             +"You probably don't have appropriate permissions \n"
  175.             +"(write access to your profile or chrome directory). \n"
  176.             +"_____________________________\nError code:" + errJar);
  177.         cancelInstall(errJar);
  178.     }
  179.     
  180. }